/**
 * 
 */
package org.openwork.portlet.skills.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.openwork.portlet.action.BaseAction;
import org.openwork.portlet.skillmanagement.model.Skill;
import org.openwork.portlet.skillmanagement.service.SkillLocalServiceUtil;

import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;

/**
 * @author samuelgmartinez
 *
 */
public class AjaxViewSkillsAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7554333340749452120L;

	@Override
	public String execute() throws Exception {
		HttpServletRequest request = getServletRequest();		
		String skillCategoryId = ParamUtil.get(request, WebKeys.SKILL_CAT_ID_PARAM, StringPool.BLANK);
		
		if(Validator.isNotNull(skillCategoryId) && Validator.isNumber(skillCategoryId)) {
			List<Skill> skills = SkillLocalServiceUtil.searchByCategoryId(GetterUtil.getLong(skillCategoryId));
			request.setAttribute(WebKeys.SKILL_LIST_ATTR, skills);
		}
		
		return SUCCESS;
	}	
	
}
